package com.yonyou.crm.sact.actrecord.service;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import org.springframework.stereotype.Service;

import com.yonyou.crm.common.biz.service.BaseBizServiceImpl;
import com.yonyou.crm.common.login.context.LoginContextConstant;
import com.yonyou.crm.common.page.entity.Page;
import com.yonyou.crm.sact.actrecord.entity.ActRecordVO;
import com.yonyou.iuap.context.InvocationInfoProxy;

@Service
public class ActRecordBizServiceImpl extends BaseBizServiceImpl<ActRecordVO>{
	
	public Page<ActRecordVO> getPage(Page<ActRecordVO> page, Map<String, Object> paramMap){
		Page<ActRecordVO> actRecordPage = null;
		if (paramMap == null) {
			paramMap = new HashMap<String, Object>();
		}
		paramMap.put("tenantId", InvocationInfoProxy.getTenantid());
		actRecordPage = super.pageSelect(ActRecordVO.class, page, paramMap.keySet().toArray(new String[0]), paramMap.values().toArray(new Object[0]));
		return actRecordPage;
	}
	
	@Override
	protected void beforeSaveVO(ActRecordVO vo) {
		
		super.beforeSaveVO(vo);
		
		//添加默认负责人
		Long ownerUserId = vo.getOwnerUserId();
		if (ownerUserId == null || ownerUserId == 0) {
			Long userId = new Long(InvocationInfoProxy.getParameter(LoginContextConstant.UserId));
			vo.setOwnerUserId(userId);
		}
		
		//添加默认行动记录时间
		Date recordDate = vo.getRecordDate();
		if (recordDate == null) {
			vo.setRecordDate(new Date());
		}
		
	}
	
	public ActRecordVO save(ActRecordVO vo){
		return super.saveVO(vo);
	}
	
	public Page<ActRecordVO> batchDelete(String[] ids, Page<ActRecordVO> page, Map<String, Object> paramMap){
		super.batchDeleteByIDs(ActRecordVO.class, ids);
		Page<ActRecordVO> actRecordPage = getPage(page, paramMap);
		return actRecordPage;
	}
	
	public ActRecordVO update(ActRecordVO vo){
		return super.updateVO(vo);
	}
	
	public ActRecordVO detail(Long id){
		
		
		
		return super.getVOById(ActRecordVO.class, id);
	}
}
